from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session

from app import crud, models, schemas
from app.api import deps

router = APIRouter()


@router.get("/balance", response_model=schemas.User)
def read_user_balance(
    db: Session = Depends(deps.get_db),
    current_user: models.User = Depends(deps.get_current_user),
) -> any:
    """
    Get current user's credit balance.
    """
    return current_user


@router.get("/transactions", response_model=list[schemas.CreditTransaction])
def read_user_transactions(
    db: Session = Depends(deps.get_db),
    current_user: models.User = Depends(deps.get_current_user),
    skip: int = 0,
    limit: int = 100,
) -> any:
    """
    Retrieve credit transactions for the current user.
    """
    transactions = crud.get_transactions_by_user(
        db, user_id=current_user.id, skip=skip, limit=limit
    )
    return transactions
